package org.jeecg.modules.wangyue.controller.sys;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.wangyue.constant.DelFlagConstant;
import org.jeecg.modules.wangyue.entity.Configuration;
import org.jeecg.modules.wangyue.service.IConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import java.util.List;
import java.util.Map;

/**
* @Description: 基础设置管理
* @Author: jeecg-boot
* @Date:   2023-06-30
* @Version: V1.0
*/
@Slf4j
@Api(tags="基础设置管理")
@RestController
@RequestMapping("/wangyue/sys/configuration")
@Validated
public class ConfigurationManageController extends JeecgController<Configuration, IConfigurationService> {
   @Autowired
   private IConfigurationService configurationService;

    /**
     * 基础设置管理-查询参数
     * @return
     */
   @AutoLog(value = "基础设置管理-查询参数")
   @ApiOperation(value="基础设置管理-查询参数", notes="基础设置管理-查询参数")
   @GetMapping(value = "/findConfigurationAll")
   public Result<?> findConfigurationAll() {
       QueryWrapper<Configuration> queryWrapper = new QueryWrapper<>();
       queryWrapper.eq("del_flag", DelFlagConstant.normal);
       return Result.OK("查询成功", configurationService.list(queryWrapper));
   }



    /**
     * 基础设置管理-保存
     *
     * @param configurationArrMap
     * @return
     */
    @AutoLog(value = "基础设置管理-保存")
    @ApiOperation(value="基础设置管理-保存", notes="基础设置管理-保存")
    @PostMapping(value = "/save")
    public Result<?> save(@RequestBody Map<String, Object> configurationArrMap) {
        String configurationArrStr = JSONObject.toJSONString(configurationArrMap.get("configurationArr"));
        List<Configuration> rakebackList = JSONObject.parseArray(configurationArrStr, Configuration.class);
        configurationService.saveOrUpdateBatch(rakebackList);
        return Result.OK("保存成功！");
    }



}
